package com.pktechan.manage.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pktechan.manage.entity.CloudPoint;
import com.pktechan.manage.service.CloudPointFlowService;
import com.pktechan.manage.service.CloudPointService;
import com.pktechan.manage.utils.HtmlUtil;
import com.pktechan.manage.vo.CloudPointFlowVo;
import com.pktechan.manage.vo.CloudPointVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @program: cloudfloating
 * @description: 产品相关功能
 * @author: s.zhang
 * @create: 2021-03-10 10:17
 **/
@Controller
@RequestMapping("cloudPointController")
public class CloudPointController {

    private static final Logger logger = LoggerFactory.getLogger(CloudPointController.class);

    @Autowired
    private CloudPointService cloudPointService;
    @Autowired
    private CloudPointFlowService cloudPointFlowService;

    /**
     * 查询客户积分管理列表
     *
     * @param cloudPointVo
     * @param response
     */
    @RequestMapping(value = "getCloudPointVoList", method = RequestMethod.POST)
    public void getCloudPointVoList(@RequestBody CloudPointVo cloudPointVo, HttpServletResponse response) {
        try {
            logger.info("查询客户积分管理列表");
            PageHelper.startPage(cloudPointVo.getPageNo(), cloudPointVo.getPageSize());
            List<CloudPointVo> list = cloudPointService.getCloudPointVoList(cloudPointVo);
            PageInfo pageInfo = new PageInfo(list);
            HtmlUtil.writerSuccessJson(response, pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            logger.debug(e.getMessage());
            HtmlUtil.writerFailJson(response, e.getMessage());
        }
    }
    /**
     * 查询积分流水管理列表
     *
     * @param cloudPointFlowVo
     * @param response
     */
    @RequestMapping(value = "getCloudPointFlowVoList", method = RequestMethod.POST)
    public void getCloudPointFlowVoList(@RequestBody CloudPointFlowVo cloudPointFlowVo, HttpServletResponse response) {
        try {
            logger.info("查询积分流水管理列表");
            PageHelper.startPage(cloudPointFlowVo.getPageNo(), cloudPointFlowVo.getPageSize());
            List<CloudPointFlowVo> list = cloudPointFlowService.getCloudPointFlowVoList(cloudPointFlowVo);
            PageInfo pageInfo = new PageInfo(list);
            HtmlUtil.writerSuccessJson(response, pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            logger.debug(e.getMessage());
            HtmlUtil.writerFailJson(response, e.getMessage());
        }
    }

    /**
     * 打开积分流水管理页面
     * @return
     */
    @RequestMapping("toCloudPointFlowVoList")
    public String toCloudPointFlowVoList() {
        return "cloudPoint/cloudPointFlowVoList";
    }
    /**
     * 打开积分流水管理页面
     * @return
     */
    @RequestMapping("toCloudPointVoList")
    public String toCloudPointVoList() {
        return "cloudPoint/cloudPointVoList";
    }
    /**
     * 根据Id修改积分信息
     *
     * @param cloudPoint
     * @param response
     */
    @RequestMapping(value = "updateCloudPointById", method = RequestMethod.POST)
    public void updateCloudPointById(@RequestBody CloudPoint cloudPoint, HttpServletResponse response) {
        try {
            logger.info("根据Id="+cloudPoint.getId()+"修改积分信息");
            cloudPointService.update(cloudPoint);
            HtmlUtil.writerSuccessJson(response);
        } catch (Exception e) {
            e.printStackTrace();
            logger.debug(e.getMessage());
            HtmlUtil.writerFailJson(response, e.getMessage());
        }
    }
}
